window.onload = function(params) {
	var canvas = document.getElementById('canvas');
	var ctx = canvas.getContext('2d');

	var width = canvas.width - 4,
		height = canvas.height - 4;
	console.log(width, height);
	// 绘制框架
	// ctx.strokeStyle = '#eee';
	ctx.strokeRect(0.5, 0.5, width, height);

	jsonp(
		'https://hsmarket.eastmoney.com/api/shszminutequote?id=603123&market=SH',
		function(data) {
			resolveData(data);
		},
		function() {
			console.log('error');
		},
		10000
	);
};

function resolveData(data) {}

function renderData(data) {}

function jsonp(url, sucFn, errFn, timeout) {
	var scriptElement = document.createElement('script'),
		timeoutTimer = -1,
		randCode = Date.now(),
		callbackName = '_em_quotationdata_' + randCode;

	var clear = function() {
		scriptElement && scriptElement.parentNode.removeChild(scriptElement);
		window[callbackName] && delete window[callbackName];
	};

	scriptElement.onerror = function() {
		clearTimeout(timeoutTimer);
		clear();
		errFn && errFn();
	};

	window[callbackName] = function(data) {
		clearTimeout();
		clear();
		sucFn && sucFn(data);
	};

	if (timeout) {
		timeoutTimer = setTimeout(function() {
			clear();
			errFn && errFn();
		}, timeout);
	}

	scriptElement.src = [ url, '&callback=', callbackName ].join('');
	document.getElementsByTagName('head').item(0).appendChild(scriptElement);
}
